import java.util.HashMap;
import java.util.Map;

class Solution {
    public int findMaxLength(int[] nums) {
        int n=nums.length,count=0;
        int len=0;
        Map<Integer,Integer> hash=new HashMap<>();

        for(int i=0;i<n;i++){
            hash.put(nums[i],hash.getOrDefault(nums[i],0)+1);
        }
        int zero=hash.getOrDefault(0,0);
        int one=hash.getOrDefault(1,0);
        if(zero==one){
            return zero;
        }else len=Math.min(zero,one);
        return len+len;
    }
}

public class a{
    public static void main(String[] args) {
       int[] nums={0,1,1,0,1,1,1,0};
      int a=new Solution().findMaxLength(nums);
        System.out.println(a);
    }
}

